{capture name="trAreYouSureToDelete"}[[Are you sure you want to delete selected item(s)?]]{/capture}
{capture name="trChooseActionFirst"}[[Please choose an action first]]{/capture}
{capture name="trSelectItemFirst"}[[Please select item(s) first]]{/capture}
{capture name="trInformation"}[[Information]]{/capture}
<script type="text/javascript">
{literal}
	$.ui.dialog.prototype.options.bgiframe = true;

	function showDialogMessage(message){
		var dialog = $("#dialog");
		dialog.dialog('destroy');
		dialog.attr({title: "{/literal}{$smarty.capture.trInformation|escape:"javascript"}{literal}"});
		dialog.html(message).dialog({width: 300});
	}

	function go(button){
    	var selectedActionButtonVal = $("#selectedAction_"+button).val();
		if(! $("input:checked").length){
			showDialogMessage("{/literal}{$smarty.capture.trSelectItemFirst|escape:"javascript"}{literal}");
        }
		else if(! selectedActionButtonVal){
			showDialogMessage("{/literal}{$smarty.capture.trChooseActionFirst|escape:"javascript"}{literal}");
		}
		else{
			switch ( selectedActionButtonVal ) {
				case 'delete':
					if ( !confirm('{/literal}{$smarty.capture.trAreYouSureToDelete|escape:"javascript"}{literal}') )
						break;
				default:
					document.getElementById('action_name').value = selectedActionButtonVal;
					var form = document.guestAlerts_form;
					form.submit();
			}
		}
	}
{/literal}
</script>

<div id="dialog" style="display: none"></div>

<div class="clr"><br/></div>
{if !empty($errors)}
	{foreach from=$errors item="error"}
	<p class="error">[[{$error}]]</p>
	{/foreach}
{/if}
<div class="clr"><br/></div>
<form method="post" name="guestAlerts_form">
    <div class="box" id="displayResults">
        <div class="box-header">
            <div class="resultsnumber"></div>
            <div class="actionWithSelected">
                <input type="hidden" name="action_name" id="action_name" value="" />
                <div style="display:inline-block;">
                    <div class="actionSelected">
                        <label for="selectedAction_up">[[Actions with Selected]]:</label>
                        <select id="selectedAction_up" name="selectedAction_up">
                            <option value="">[[Select action]]</option>
                            <option value="activate">[[Activate]]</option>
                            <option value="deactivate">[[Deactivate]]</option>
                            <option value="confirm">[[Confirm]]</option>
                            <option value="delete">[[Delete]]</option>
                        </select>
                        <input type="button" value="Go" class="grayButton" onclick="go('up');"/>
                    </div>
                </div>
            </div>
            <div class="pagination">
                {foreach from=$pages item=page}
                    {if $page == $currentPage}
                        <strong>{$page}</strong>
                    {else}
                        {if $page == $totalPages && $currentPage < $totalPages-3} ... {/if}
                        <a href="?page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&amp;alerts_per_page={$alerts_per_page}{$searchFields}">{$page}</a>
                        {if $page == 1 && $currentPage > 4} ... {/if}
                    {/if}
                {/foreach}
            </div>
            <div class="numberPerPage">
                <label for="alerts_per_page">[[per page]]:</label>
                <select id="alerts_per_page" name="alerts_per_page" onchange="window.location = '?restore=1{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&alerts_per_page='+this.value;" class="perPage">
                    <option value="10" {if $alerts_per_page == 10}selected="selected"{/if}>10</option>
                    <option value="20" {if $alerts_per_page == 20}selected="selected"{/if}>20</option>
                    <option value="50" {if $alerts_per_page == 50}selected="selected"{/if}>50</option>
                    <option value="100" {if $alerts_per_page == 100}selected="selected"{/if}>100</option>
                </select>
            </div>
        </div>
		{capture name="sortingOrderImg"}{if $sorting_order == 'ASC'}<img src="{image}b_up_arrow.gif" />{else}<img src="{image}b_down_arrow.gif" />{/if}{/capture}
        <div class="innerpadding">
            <div id="displayResultsTable">
                <table width="100%">
                    <thead>
                        <tr>
                            <th width="1%"><input type="checkbox" id="all_checkboxes_control" /></th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=sid&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'sid'}DESC{else}ASC{/if}&amp;alerts_per_page={$alerts_per_page}">[[ID]]</a>
								{if $sorting_field == 'sid'}{$smarty.capture.sortingOrderImg}{/if}
                            </th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=email&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'email'}DESC{else}ASC{/if}&amp;alerts_per_page={$alerts_per_page}">[[Email]]</a>
								{if $sorting_field == 'email'}{$smarty.capture.sortingOrderImg}{/if}
                            </th>
							<th>[[Alert Type]]</th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=email_frequency&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'email_frequency'}DESC{else}ASC{/if}&amp;alerts_per_page={$alerts_per_page}">[[Email frequency]]</a>
								{if $sorting_field == 'email_frequency'}{$smarty.capture.sortingOrderImg}{/if}
                            </th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=subscription_date&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'subscription_date'}DESC{else}ASC{/if}&amp;alerts_per_page={$alerts_per_page}">[[Subscription date]]</a>
								{if $sorting_field == 'subscription_date'}{$smarty.capture.sortingOrderImg}{/if}
                            </th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=status&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'status'}DESC{else}ASC{/if}&amp;alerts_per_page={$alerts_per_page}">[[Status]]</a>
								{if $sorting_field == 'status'}{$smarty.capture.sortingOrderImg}{/if}
                            </th>
                            <th colspan="2" class="actions" width="10%">[[Actions]]</th>
                        </tr>
                    </thead>
                    {foreach from=$guestAlerts item=guestAlert name=alerts_block}
                        <tr class="{cycle values = 'evenrow,oddrow'}" id="guestAlerts[{$guestAlert.sid}]">
                            <td><input type="checkbox" name="guestAlerts[]" value="{$guestAlert.sid}" id="checkbox_{$smarty.foreach.alerts_block.iteration}" /></td>
                            <td><strong>{$guestAlert.sid}</strong></td>
                            <td><strong><a href="mailto:{$guestAlert.email}">{$guestAlert.email}</a></strong></td>
                            <td>{$guestAlert.listing_type_id}</td>
                            <td>[[{$guestAlert.email_frequency}]]</b></td>
                            <td>{$guestAlert.subscription_date}</td>
                            <td>
								{if $guestAlert.status == "unsubscribed"}
									[[Unsubscribed]]
								{elseif $guestAlert.status == "unconfirmed"}
									<span class="color-red">[[Not Confirmed]]</span>
								{elseif $guestAlert.status == "inactive"}
                                    [[Not Active]]
								{else}
                                    [[Active]]
								{/if}
							</td>
							{* ACTIONS >>> *}
                            <td>
								{if $guestAlert.status eq "unconfirmed"}
									<a href="{$GLOBALS.site_url}/guest-alerts/?action_name=confirm&amp;guestAlerts[]={$guestAlert.sid}" title="[[Confirm]]" class="editbutton">[[Confirm]]</a>
								{elseif $guestAlert.status eq "active"}
									<a href="{$GLOBALS.site_url}/guest-alerts/?action_name=deactivate&amp;guestAlerts[]={$guestAlert.sid}" title="[[Deactivate]]" class="deletebutton">[[Deactivate]]</a>
								{elseif $guestAlert.status eq "inactive"}
                                    <a href="{$GLOBALS.site_url}/guest-alerts/?action_name=activate&amp;guestAlerts[]={$guestAlert.sid}" title="[[Activate]]" class="editbutton">[[Activate]]</a>
								{/if}
							</td>
                            <td>
								<a href="{$GLOBALS.site_url}/guest-alerts/?action_name=delete&amp;guestAlerts[]={$guestAlert.sid}" title="[[Delete]]" class="deletebutton"
										onclick="return confirm('{$smarty.capture.trAreYouSureToDelete|escape:"javascript"}');">[[Delete]]</a>
                            </td>
                        </tr>
                    {/foreach}
                </table>
            </div>
        </div>
        <div class="box-footer">
            <div class="resultsnumber"></div>
            <div class="actionWithSelected">
                <label for="selectedAction_down">[[Actions with Selected]]:</label>
                <select id="selectedAction_down" name="selectedAction_down" >
                    <option value="">[[Select action]]</option>
                    <option value="activate">[[Activate]]</option>
                    <option value="deactivate">[[Deactivate]]</option>
                    <option value="confirm">[[Confirm]]</option>
                    <option value="delete">[[Delete]]</option>
                </select>
                <input type="button" value="Go" class="greenButton" onclick="go('down');" />
            </div>
            <div class="pagination">
                {foreach from=$pages item=page}
                    {if $page == $currentPage}
                        <strong>{$page}</strong>
                    {else}
                        {if $page == $totalPages && $currentPage < $totalPages-3} ... {/if}
                        <a href="?page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&amp;alerts_per_page={$alerts_per_page}{$searchFields}">{$page}</a>
                        {if $page == 1 && $currentPage > 4} ... {/if}
                    {/if}
                {/foreach}
            </div>
        </div>
    </div>
</form>

<div id="stat-footer">
	<form method="post" action="{$GLOBALS.site_url}/guest-alerts/export/">
		<input type="hidden" name="sorting_field" value="{$sorting_field}"/>
		<input type="hidden" name="sorting_order" value="{$sorting_order}"/>
		<input type="submit" name="export" value="[[Export in]]" class="grayButton" /> &nbsp;
		<select name="type" style="width:60px; float: right;">
			<option value="csv">CSV</option>
			<option value="xls">XLS</option>
		</select>
	</form>
	<div class="clr"></div>
</div>

<script type="text/javascript">
	var total={if $smarty.foreach.alerts_block.total}{$smarty.foreach.alerts_block.total}{else}0{/if};
	{literal}
	function set_checkbox(param) {
		for (i = 1; i <= total; i++) {
			if (checkbox = document.getElementById('checkbox_' + i)) {
				checkbox.checked = param;
			}
		}
	}

	$("#all_checkboxes_control").click(function() {
        var trGuestAlerts = $("tr[id^='guestAlerts']");
        if (this.checked == false){
			set_checkbox(false);
		} else {
			set_checkbox(true);
		}
	});

	{/literal}
</script>